package com.tqw.order.listener;

import com.tqw.order.constants.OrderConstant;
import com.tqw.order.mapper.OrderMapper;
import com.tqw.order.service.OrderService;
import com.tqw.order.vo.OrderPayInfoVO;
import com.tqw.pojo.Order;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @Author: czm
 * @Date: 2022/04/15/20:49
 * @Description:订单服务消息消费者
 */
@Component
@RocketMQMessageListener(topic = OrderConstant.ORDER_CANCEL_TOPIC,consumerGroup = OrderConstant.ORDER_CANCEL_TOPIC)
public class OrderCancelConsumer implements RocketMQListener<String> {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public void onMessage(String orderId) {
        Order orderInfo = orderMapper.getOrderInfoByOrderId(orderId);
        //如果订单未支付,将订单设为取消状态
        if (OrderConstant.ORDER_NO_PAY.equals(orderInfo.getStatus())){
            orderService.cancel(orderId);
        }

    }
}
